const path = require("path")
const resolve = require("rollup-plugin-node-resolve")
const commonjs = require("rollup-plugin-commonjs")
const babel = require("rollup-plugin-babel")
const json = require("@rollup/plugin-json")
const vue = require("rollup-plugin-vue")
const postcss = require("rollup-plugin-postcss")
const terser = require("@rollup/plugin-terser")
const inputPath = path.resolve(__dirname, "./src/index.js")
const outputUmdPath = path.resolve(__dirname, "./dist/kpzc.datav.min.js")
const outputEsPath = path.resolve(__dirname, "./dist/kpzc.datav.es.min.js")

module.exports = {
  input: inputPath,
  output: [
    {
      file: outputUmdPath,
      format: "umd",
      name: "kpzcDatav",
      globals: {
        vue: "vue"
      }
    },
    {
      file: outputEsPath,
      format: "es",
      globals: {
        vue: "vue"
      }
    }
  ],
  plugins: [
    vue(),
    // resolve 解决打包安装第三方依赖问题
    resolve(),
    // rollup.js是无法识别CommonJS模块的 使用rollup-plugin-commonjs
    commonjs(),
    babel({
      exclude: "node_modules/**", // 不进行babel编译
      runtimeHelpers: true,
      plugins: [
        [
          "@babel/transform-runtime",
          {
            regenerator: true
          }
        ]
      ]
    }),
    // 支持打包json
    json(),
    postcss({
      plugins: []
    }),
    // 压缩
    terser()
  ],
  external: ["vue"]
}
